﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DotNetExtensions.Core.Invoker
{
    [AttributeUsage(AttributeTargets.Method)]
    public class MethodDescriptionAttribute : Attribute
    {
        public string[] Names { get; set; }
        public string[] Descriptions { get; set; }

        private Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
        public string Get(string key)
        {
            if (keyValuePairs.ContainsKey(key)) return keyValuePairs[key];
            return null;
        }
        public string this[string key] => Get(key);
        /// <summary>
        /// [K,V,K,V,K,V]格式
        /// </summary>
        /// <param name="descriptions">[K,V,K,V,K,V]</param>
        public MethodDescriptionAttribute(params string[] descriptions)
        {
            if (descriptions != null && descriptions.Length > 0)
            {
                int length = descriptions.Length / 2;
                Names = new string[length];
                Descriptions = new string[length];
                for (int i = 0; i < length * 2; i++)
                {
                    if (i % 2 == 0) Names[i / 2] = descriptions[i]; // 0 2 4 -> 0 1 2
                    if (i % 2 == 1) Descriptions[(i - 1) / 2] = descriptions[i];// 1 3 5 -> 0 1 2
                }

                for (int i = 0; i < length; i++)
                {
                    keyValuePairs.Add(Names[i], Descriptions[i]);
                }
            }
        }
        public MethodDescriptionAttribute()
        {

        }
    }
    public class MethodParameter : Attribute
    {
        public MethodParameter(string name, string description)
        {
            this.Name = name;
            this.Description = description;
        }
        public string Name { get; set; }
        public string Description { get; set; }
    }
}
